<template>
  <div>
    <h3>陈志豪黑店</h3>

    <!-- 使用子组件 -->
    <MyProduct
      v-for="item in list"
      :key="item.id"
      :price="item.proprice"
      :desc="item.desc"
      :uname="item.proname"
      :id="item.id"
      @sayPrice="fatherSayPrice"
    ></MyProduct>
  </div>
</template>

<script>
import MyProduct from './components/my-product.vue'

export default {
  components: {
    MyProduct
  },

  data() {
    return {
      list: [
        {
          id: 1,
          proname: '超级好吃棒棒糖',
          proprice: 188,
          low: 160,
          desc: '甜'
        },
        {
          id: 2,
          proname: '超级好吃的大鸡腿',
          proprice: 360,
          low: 320,
          desc: '香'
        },
        { id: 3, proname: '超级无敌冰激凌', proprice: 42, low: 30, desc: '冰' }
      ]
    }
  },

  methods: {
    fatherSayPrice(id, num) {
      console.log('我是父组件里的事件')
      // console.log(id)

      this.list.forEach((item) => {
        if (item.id === id) {
          item.proprice > item.low
            ? (item.proprice -= num)
            : alert('陈志豪要破产了，别砍了')
        }
      })
    }
  }
}
</script>

<style>
</style>